package com.aerfafish.spider.neo4j.repository;

import com.aerfafish.spider.neo4j.dao.Fund;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author aerfafish
 * @date 2021/4/20 7:10 下午
 */
@Component
public interface FundRepository extends Neo4jRepository<Fund, Long> {

    @Query("match (fund:Fund{code:$code}) return fund")
    List<Fund> queryFundByCode(@Param("code") String code);

    @Query("merge (fund:Fund{code:$code}) set fund.type=$type, fund.assetSize=$assetSize")
    void save(@Param("code") String code, @Param("type") String type, @Param("assetSize") Long assetSize);

    @Query("merge (fund:Fund{code:$code}) set fund.assetSize=$assetSize")
    void save(@Param("code") String code, @Param("assetSize") Long assetSize);


    @Query("merge (fund:Fund{code:$code}) set fund.type=$type")
    void save(@Param("code") String code, @Param("type") String type);


    @Query("merge (fund:Fund{code:$code}) set fund.type=$type, fund.assetSize=$assetSize " +
            "merge (date:Date{date: $date}) " +
            "merge p = (fund)-[r:FUND_ESTABLISH_DATE]-> (date)")
    void save(@Param("code") String code, @Param("type") String type, @Param("assetSize") Long assetSize,
              @Param("date") String date);


    @Query("match (fund:Fund) return fund.code")
    List<String> queryAllFund();
}
